<?php use_helper('Form') ?>
<script>
  $(document).ready(function() {
     var tip = $('#tip').val();
     if(tip == 4 || tip == 5)
       $('#razred').removeClass('hide');
     else $('#razred').addClass('hide');

     $('#razred_id').val(<?php echo $sf_request->getParameter('razred_id') ?>);
  });

  function shRazred(tip)
  {
     if(tip == 4 || tip == 5)
       $('#razred').removeClass('hide');
     else $('#razred').addClass('hide');
     $('.profil_row').addClass('hide');
  }

  function hide_row()
  {
     $('.profil_row').addClass('hide');
  }

  function loadRazreds(skola_id)
  {
     $('.profil_row').addClass('hide');
     $.ajax({
      type: "POST",
      url: "/uprava.php/stampa/loadRazreds",
      data: "skola_id=" + skola_id,
      success: function(msg){
        if(msg)
        {
            $('#razred').html(msg);
        }
      }
    });
  }

  function stampajKorPodatke(mode, id)
  {
     var skola_id = $('#skola_id').val();
     var razred_id = $('#razred_id').val();
     var tip = $('#tip').val();
     if(mode > 1)
     {
        href = '/uprava.php/stampa/vise/';
        href += 'skola_id/' + skola_id;
        href += '/tip/' + tip;
        href += '/razred_id/' + razred_id;
        window.open(href, 'Stampa', "width=1024,height=768,scrollbars=yes");
     }

     else
     {
        href = '/uprava.php/stampa/jedan/';
        href += 'skola_id/' + skola_id;
        href += '/tip/' + tip;
        href += '/id/' + id;
        window.open(href, 'Stampa', "width=1024,height=768,scrollbars=yes");
     }
  }
</script>

<table class="statistike" cellspacing="0" cellpadding="0" border="1" width="1050" style="border-collapse: collapse; empty-cells: show;">
  <tr>
    <th colspan="8">
      <form method="post" name="sel">
        <?php if(count($skola_list) > 1) echo select_tag('skola_id', options_for_select($skola_list, $sf_request->getParameter('skola_id')), array('onChange' => 'loadRazreds(this.value)')); else echo '<input type="hidden" name="skola_id" id="skola_id" value="'.$skola_id.'" />'; ?>
        <?php echo select_tag('tip', options_for_select($profil_tips, $sf_request->getParameter('tip')), array('onChange' => 'shRazred(this.value)')) ?>
        <span id="razred" class="hide"><?php echo $raz_select ?></span>
        <button type="submit" class="button">Pregled</button>
        <button class="button" onclick="stampajKorPodatke(2, 0)">Štampa</button>
      </form>
    </th>
  </tr>

  <tr>
    <th>Prezime i ime</th>
    <th>Razred</th>
    <th>Adresa</th>
    <th>Telefon</th>
    <th>Mobilni</th>
    <th>Username</th>
    <th>Email</th>
    <th>Akcije</th>
  </tr>

  <?php foreach($profils as $profil){?>
  <tr class="profil_row">
    <th class="left_al"><?php echo ($sf_request->getParameter('tip') != ProfilPeer::$tip['roditelj'])? $profil : KorisnickiPodaci::getRoditeljIme($profil) ?></th>
    <td><?php echo ($profil->getColumn('RazredR'))?RazredPeer::razredRimski($profil->getColumn('RazredR')).' - '.$profil->getColumn('RazredS'):'' ?></td>
    <td class="left_al"><?php echo $profil->getAdresa() ?></td>
    <td class="left_al"><?php echo $profil->getTelefon() ?></td>
    <td class="left_al"><?php echo $profil->getMobilni() ?></td>
    <td class="left_al"><?php echo $profil->getUsername() ?></td>
    <td class="left_al"><?php echo $profil->getEMail() ?></th>
    <th><a id="<?php echo $profil->getId() ?>" href="javascript: void(0)" onclick="stampajKorPodatke(1, this.id)">Print</a></td>
  </tr>
  <?php }?>

</table>